package org.university.entity;

import io.swagger.annotations.ApiModelProperty;
import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.hibernate.validator.constraints.Length;
import org.university.enums.GlobalEnums;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * @TableName enrollment
 */
@Entity
@Table(name = "enrollment")
@Data
@SQLDelete(sql = "UPDATE enrollment SET deleted = true WHERE enrollment_id = ?") // 软删除SQL
@Where(clause = "deleted = false")
public class Enrollment implements Serializable {

    /**
     *
     */
    @Id
    @NotNull(message = "[]不能为空")
    @ApiModelProperty("")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer enrollmentId;
    /**
     * 学号
     */
    @NotBlank(message = "[学号]不能为空")
    @Size(max = 20, message = "编码长度不能超过20")
    @ApiModelProperty("学号")
    @Length(max = 20, message = "编码长度不能超过20")
    private String studentId;
    /**
     * 班级ID
     */
    // @NotNull(message = "[班级ID]不能为空")
    // @ApiModelProperty("班级ID")
    // private Integer classId;
    @ManyToOne
    @JoinColumn(name = "class_id")
    private TeachingClass teachingClass; // 关键关联
    /**
     * 选课日期
     */
    @NotNull(message = "[选课日期]不能为空")
    @ApiModelProperty("选课日期")
    private LocalDate enrollmentDate;
    /**
     *
     */
    @ApiModelProperty("")
    private BigDecimal score;
    /**
     * 课程状态
     */
    @NotNull(message = "[课程状态]不能为空")
    @ApiModelProperty("课程状态")
    @Enumerated(EnumType.STRING) // 存储枚举的名称（如 "SELECTED"）
    // 或 @Enumerated(EnumType.ORDINAL) 存储枚举的序号（如 1, 2, 3）
    private GlobalEnums.Status status;

    @Column(name = "deleted", columnDefinition = "tinyint(1) default 0")
    @ApiModelProperty("是否已删除")
    private Integer deleted = 0;
}
